package com.piz.web.user;

import java.security.Principal;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller

public class LoginController {
	@RequestMapping(value = "login.action", method = RequestMethod.GET)
	public ModelAndView login(){
		return new ModelAndView("user/login");
	}
	
	@RequestMapping(value = "welcome.action")
	public ModelAndView welcom(Model model, Principal principal ){
		
		String username;
		if(principal != null)
		{
			 username = principal.getName();
			model.addAttribute("username", username);
		}
		return new ModelAndView("user/homepage");
	}
	
	@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
	public ModelAndView loginfailed(Model model) {
 
		model.addAttribute("error", "Please input correct username and password to login");
		return new ModelAndView("user/login");
 
	}
 
}
